<?php

namespace App\Http\Requests\Backend;

use Illuminate\Foundation\Http\FormRequest;

class ProjectRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->method()) {
            // CREATE
            case 'POST':
                return [
                    'project_name' => 'required',
                    'project_type_id' => 'required',
                    'project_cover' => 'required',
                    'project_desc' => 'required',
                    'is_show' => 'required',
                ];
            case 'PUT':
                return [
                    'id' => 'required',
                    'project_name' => 'required',
                    'project_type_id' => 'required',
                    'project_cover' => 'required',
                    'project_desc' => 'required',
                    'is_show' => 'required',
                ];
            default:
                return [];
        }
    }

    public function messages()
    {
        return [
            'id.required' => '主键不能为空！',
            'project_name.required' => '项目名称不能为空！',
            'project_type_id.required' => '项目类型不能为空！',
            'project_cover.required' => '请上传项目封面！',
            'project_desc.required' => '请输入项目描述！',
            'is_show.required' => '请选择是否显示！',
        ];
    }
}
